package com.nus;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

import com.nus.parsers.ParserAPIs;
import com.nus.representations.IvleNews;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class IvleNews_Details_Activity extends Activity implements OnClickListener {
	public ImageButton home;
	protected TextView title;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.ivlenewsdetails);
		 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
		 title = (TextView) findViewById(R.id.titleheader);
		 title.setText("News");
		ImageView b = (ImageView)findViewById(R.id.home);
	  b.setImageDrawable(getResources().getDrawable(R.drawable.news));
		boolean netconn = checkInternetConnection();
		//home = (ImageButton) findViewById(R.id.home);
//        home.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				//Intent goHome = new Intent(Intent.ACTION_MAIN);
//				//goHome.setClass(IvleNews_Details_Activity.this, OptionsActivity.class);
//				//goHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//			//	startActivity(new Intent("com.nus.OptionsActivity"));
//				
//			}	
//		});
		if(!netconn){
			Toast.makeText(getApplicationContext(), "Please check your internet or 3G connection", Toast.LENGTH_LONG).show();       
        }
		final TextView textView = (TextView) findViewById(R.id.newstitle);
		if(!IvleNewsActivity.news_title.equals(""))
			textView.setText(IvleNewsActivity.news_title);
		else
			textView.setText("-");
		
		final TextView textView1 = (TextView) findViewById(R.id.news_creationdate);
		textView1.setTextColor(Color.BLUE);
		if(!IvleNewsActivity.news_creationdate.equals(""))
			textView1.setText(IvleNewsActivity.news_creationdate);
		else
			textView1.setText("-");
		
		final TextView textView2 = (TextView) findViewById(R.id.ivlenewsdetails);
		if(!IvleNewsActivity.news_description.equals("")){
			textView2.setText(Html.fromHtml(IvleNewsActivity.news_description));
			textView2.setMovementMethod(LinkMovementMethod.getInstance());
			textView2.setMovementMethod(ScrollingMovementMethod.getInstance());
		}
		else
			textView2.setText("-");
	}
	public boolean checkInternetConnection() {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) {
            return true;

        } else {
            return false;
        }
    }
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
	}

}
